import {request} from "@umijs/max";


export async function getCustomers(params: Customer.GetCustomersParams, options?: { [key: string]: any }) {
  // 将 params 对象转换为查询字符串
  const queryString = new URLSearchParams(params as any).toString();

  return request<{
    data: Customer.GetCustomersResult;
  }>(`/customer/searchCustomer?${queryString}`, {
    method: 'GET',
    ...(options || {}),
  });
}


export async function getAllCustomerLevels(options?: { [key: string]: any }) {
  return request<{
    data: CUSTOMER.GetAllCustomerLevelResult
  }>('/customer/searchCustomerLevel', {
    method: 'GET',
    ...(options || {}),
  });
}


export async function addOrUpdateCustomerLevel(params: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/customer/addOrUpdateCustomerLevel', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}

export async function getCustomerDetail(params: { [key: string]: any }, options?: { [key: string]: any }) {
  const queryString = new URLSearchParams(params as any).toString();

  return request<{
    data: CUSTOMER.GetCustomerDetailResult
  }>(`/customer/searchCustomerDetail?${queryString}`, {
    method: 'GET',
    // params: {
    //   ...params
    // },
    ...(options || {}),
  });
}
export async  function getDeptMembers(params: { [key: number]: any }, options?: { [key: string]: any }) {
  
  return request<{
    data: CUSTOMER.DeptTreeMember;
  }>(`/newMember/findMemberList/${params}`, {
    method: 'GET',
    ...(options || {}),
  });

 }




export async function updateCustomerRemark(params: CUSTOMER.UpdateCustomerRemarkParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/customer/updateCustomerRemark', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}



export async function transferCustomer(params: CUSTOMER.TransferCustomerParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/customer/transferCustomer', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}

export async function modifyCustomerLevel(params: CUSTOMER.ModifyCustomerLevelParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/customer/changeCustomerLevel', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}

export async function updateRuleState(params: CUSTOMER.InviterRuleParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/inviterRule/updateState', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}


export async function blackCustomer(params: CUSTOMER.CustomerBlackListParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/customer/setBlacklist', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}


export async function saveInviterRule(params: CUSTOMER.SaveInviterRuleParams, options?: { [key: string]: any }) {
  return request<{
    data: API.ApiResult
  }>('/inviterRule/save', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
    ...(options || {}),
  });
}

export async  function treeDepartment( options?: { [key: string]: any }) {
  return request<{
    data: CUSTOMER.DepartmentTree
  }>(`/newMember/treeDepartment`, {
    method: 'GET',
    // params: {
    //   ...params
    // },
    ...(options || {}),
  });
}


export async function getInviterRules(params: { [key: string]: any }, options?: { [key: string]: any }) {
  
  return request<{
    data: any[]
  }>(`/inviterRule/getInviterRules`, {
    method: 'GET',
    // params: {
    //   ...params
    // },
    ...(options || {}),
  }).then(res=>res.data?.[0])
}
